from common.config import *
from tests.rypark_background.get_cookie import *


class Account:
    # =====================大运营创建内部账号=====================
    # 修改密码
    def updata_pw(self, env, oldPassword, newPassword, confirmPassword):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/updatePassword"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"oldPassword": oldPassword,
                "newPassword": newPassword,
                "confirmPassword": confirmPassword}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营创建内部账号
    def creat_internal_user(self, env, account):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/addAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"account": account,
                "name": "自动化创建",
                "userType": 0}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营获取内部账号列表
    def internal_list(self, env, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/innerAccountList"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营获取内部账号详情
    def internal_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/detailAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # 大运营编辑内部账号
    def internal_updata(self, env, id, phone):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/updateAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id,
                "name": "自动化编辑",
                "phone": phone}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营启用/停用内部账号
    # status=状态（0：停用，1：启用）
    def internal_change(self, env, id, status):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/changeAccountStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营重置内部账号密码
    def internal_reset(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/resetPassword"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # =====================大运营创建商户账号=====================
    # 大运营创建商户账号
    def creat_shop_user(self, env, account):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/innerAddShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"account": account,
                "name": "自动化创建商户账号",
                "parkId": 88888888,
                "userType": 1}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营获取商户账号列表
    def internal_shop_list(self, env, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bizAccountInnerList"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营获取商户账号详情
    def internal_shop_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/detailShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # 大运营编辑商户账号
    def internal_shop_updata(self, env, id, phone=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/updateShopAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id,
                "name": "自动化编辑",
                "phone": phone,
                "parkId": 88888888}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营停用商户账号
    # status=状态（0：停用，1：启用）
    def internal_shop_change(self, env, id, status):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/changeShopAccountStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        dict = {"id": id, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 大运营重置商户账号密码
    def internal_shop_reset(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/resetShopPassword"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": internal_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # =====================商户后台创建账号=====================
    # 商户后台创建账号
    def shop_create_user(self, env, account, phone=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bsAddAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"account": account,
                "name": "自动化创建",
                "phone": phone,
                "userType": 1}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台获取账号列表
    def shop_userlist(self, env, account=None, status=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bizAccountList"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"account": account, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台获取账号详情
    def shop_detail(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bsDetailAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()

    # 商户后台编辑商户账号
    def shop_updatauser(self, env, id, phone=None):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bsUpdateAccount"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id,
                "name": "自动化编辑",
                "phone": phone}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台启用/停用账号
    # status=状态（0：停用，1：启用）
    def shop_changeuser(self, env, id, status):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bsChangeAccountStatus"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        dict = {"id": id, "status": status}
        return requests.post(url, headers=headers, json=dict).json()

    # 商户后台重置账号密码
    def shop_resetuser(self, env, id):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/bsResetPassword"
        headers = {"content-type": "application/json;charset=UTF-8",
                   "cookie": shop_cookies(env)}
        return requests.get(url, headers=headers, params={"id": id}).json()
